<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function tj(data) {
            var obj = {}
            for (i = 0; i < data.length; i++) {
                var key = data[i]
                if (obj[key]) {
                    obj[key] += 1
                } else {
                    obj[key] = 1
                }
            }
            return obj
        }

        var data = ["a","c","123","x","c","y","a","123","1","2","3","b","b"]
        console.log(tj(data));
    </script>

    <script>
        function aa(data){
            var obj1 = {}
            for(i = 0;i<data.length;i++){
                var key = data[i]
                if(obj1[key]){
                    obj1[key] +=1
                }else{
                    obj1[key] = 1
                }
            }
            return obj1
        }
        console.log(aa(["a","b","c","a"]))
    </script>

    <script>
        function bb(data){
            var dx = {}
            for(i=0;i<data.length;i++){
                var key = data[i]
                if(dx[key]){
                    // ++在前先赋值再操作，++在后先操作再赋值
                    dx[key] += 1
                }else{
                    dx[key] = 1
                }
            }
            return dx
        }

        console.log(bb(["a","a","1"]))
    </script>

    <script>
        function cc(data){
            var a = {}
            for(i=0;i<data.length;i++){
                var key = data[i]
                if(a[key]){
                    a[key] +=1;
                }else{
                    a[key] =1
                }
            }
            return a
        }
        console.log(cc(["..","aa","123","..","123"]))
    </script>
</body>

</html>